package zdream.pmfield.test.stage.effect;

import org.junit.Test;

import java.util.Map;

import zdream.pmfield.data.foe.BStat;
import zdream.pmfield.data.foe.Type;

import static zdream.pmfield.data.foe.MoveAdditionalEffects.*;

import static org.junit.Assert.*;

/**
 * @author Zdream
 * @date 2023-12-19
 * @since 0.0.1
 */
public class EffectParsedCase {
	@Test
	public void testParseFixedEffect() {
		Map<String, ?> map = parse(EffectDescription.of("fixed/STEEL/1"));
		assertEquals(1, map.size());
		assertTrue(map.containsKey(Type.STEEL.toString()));
		assertEquals(1, map.get(Type.STEEL.toString()));
	}

	@Test
	public void testParseFixedBuffEffect() {
		Map<String, ?> map = parse(EffectDescription.of("fixed-buff//flying/cover/1"));
		assertArrayEquals(new String[0], (String[]) map.get(K_FIXED_BUFF_ATTACKER_BUFFS));
		assertArrayEquals(new String[] {"flying"}, (String[]) map.get(K_FIXED_BUFF_DEFENSE_BUFFS));
		assertEquals("cover", map.get(K_FIXED_BUFF_TYPE));
		assertEquals(1, map.get(K_FIXED_BUFF_RATE));

		map = parse(EffectDescription.of("fixed-buff/flying/flying//-1"));
		assertArrayEquals(new String[] {"flying"}, (String[]) map.get(K_FIXED_BUFF_ATTACKER_BUFFS));
		assertArrayEquals(new String[] {"flying"}, (String[]) map.get(K_FIXED_BUFF_DEFENSE_BUFFS));
		assertEquals("append", map.get(K_FIXED_BUFF_TYPE));
		assertEquals(-1, map.get(K_FIXED_BUFF_RATE));
	}

	@Test
	public void testParseRemoveBuffEffect() {
		Map<String, ?> map = parse(EffectDescription.of("remove-buff/self/flying"));
		assertEquals("self", map.get(K_REMOVE_BUFF_TARGET));
		assertArrayEquals(new String[] {"flying"}, (String[]) map.get(K_REMOVE_BUFF_BUFFS));
	}

	@Test
	public void testParseApplyBuffEffect() {
		Map<String, ?> map = parse(EffectDescription.of("apply-buff/self/flying"));
		assertEquals("self", map.get(K_APPLY_BUFF_TARGET));
		assertEquals("flying", map.get(K_APPLY_BUFF_BUFF));
		assertArrayEquals(new String[] {}, (String[]) map.get(K_APPLY_BUFF_PROPERTIES));

		map = parse(EffectDescription.of("apply-buff/enemy/acid/3"));
		assertEquals("enemy", map.get(K_APPLY_BUFF_TARGET));
		assertEquals("acid", map.get(K_APPLY_BUFF_BUFF));
		assertArrayEquals(new String[] {"3"}, (String[]) map.get(K_APPLY_BUFF_PROPERTIES));
	}

	@Test
	public void testParseBStatChangeEffect() {
		Map<String, ?> map = parse(EffectDescription.of("b-stat-change/enemy/AT/1"));
		assertEquals(true, map.get(K_BSTAT_CHANGE_CHANGE));
		assertEquals("enemy", map.get(K_BSTAT_CHANGE_TARGET));
		assertEquals(1, map.get(BStat.AT.name()));
		assertEquals(3, map.size());

		map = parse(EffectDescription.of("b-stat-change/self/AT/2/SA/2/SP/2/DF/-1/SD/-1"));
		assertEquals(true, map.get(K_BSTAT_CHANGE_CHANGE));
		assertEquals("self", map.get(K_BSTAT_CHANGE_TARGET));
		assertEquals(2, map.get(BStat.AT.name()));
		assertEquals(2, map.get(BStat.SA.name()));
		assertEquals(2, map.get(BStat.SP.name()));
		assertEquals(-1, map.get(BStat.DF.name()));
		assertEquals(-1, map.get(BStat.SD.name()));
		assertEquals(7, map.size());

		map = parse(EffectDescription.of("b-stat-set/self/DF/-1"));
		assertEquals(false, map.get(K_BSTAT_CHANGE_CHANGE));
		assertEquals("self", map.get(K_BSTAT_CHANGE_TARGET));
		assertEquals(-1, map.get(BStat.DF.name()));
		assertEquals(3, map.size());
	}
}
